package com.wanlian.router.ui.integral;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.smart.android.ui.tools.BaseListFragment;
import com.wanlian.router.bean.TelecomRechargeCard;
import com.wanlian.router.net.NetWorkingClient;
import com.wanlian.router.net.ResponseData;
import com.wanlian.router.net.internal.INetCallBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Hyu on 2018/9/23.
 * Email: fvaryu@163.com
 */
public class TelecomCardFragment extends BaseListFragment {

    private List<TelecomRechargeCard> mTelecomRechargeCards;
    private TelecomCardAdapter mTelecomCardAdapter;
    public static TelecomCardFragment newInstance() {
        Bundle args = new Bundle();
        TelecomCardFragment fragment = new TelecomCardFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initUI(View view) {
        super.initUI(view);
        mTelecomRechargeCards = new ArrayList<>();
        setAdapter(mTelecomCardAdapter = new TelecomCardAdapter(getActivity(), mTelecomRechargeCards));
    }

    @Override
    protected void initData(View view) {
        super.initData(view);
    }

    @Override
    protected void loadData(final boolean isRefresh) {
        super.loadData(isRefresh);
        if (!canToLoad(isRefresh)) {
            return;
        }

        NetWorkingClient.getInstance().queryTelecomCards(getActivity(), getPageInfo(), new INetCallBack<List<TelecomRechargeCard>>() {
            @Override
            public void onFinish(ResponseData response, @Nullable List<TelecomRechargeCard> telecomRechargeCards) {
                resetPull();
                if (response.isSuccess()) {
                    if (isRefresh) {
                        mTelecomRechargeCards.clear();
                    }
                    if (telecomRechargeCards != null) {
                        mTelecomRechargeCards.addAll(telecomRechargeCards);
                    }

                    mTelecomCardAdapter.notifyDataSetChanged();
                }
            }
        });
    }
}
